package work.xiaohong.business.controller;

import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import work.xiaohong.business.feign.OrderFeign;
import work.xiaohong.business.feign.StorageFeign;
import work.xiaohong.business.to.OrderTbl;
import work.xiaohong.business.to.StorageTbl;

/**
 * @author xiaohong
 * @version 1.0
 * @date 2021/9/17 0017 13:04
 */
@SuppressWarnings("all")
@RequestMapping("/business")
@RestController
public class BusinessController {

    @Autowired
    private OrderFeign orderFeign;

    @Autowired
    private StorageFeign storageFeign;

    @GlobalTransactional
    @GetMapping
    public String business(){
        OrderTbl orderTbl = new OrderTbl();
        orderTbl.setCount(1);
        orderTbl.setCommodityCode("2001");
        orderTbl.setMoney(100);
        orderTbl.setUserId("1");
        orderFeign.add(orderTbl);

        StorageTbl storageTbl = storageFeign.findById(1).getData();
        storageTbl.setCount(storageTbl.getCount()-1);
        storageFeign.updateById(storageTbl);

        return "业务完成";
    }

}
